package com.credithc.customers.manager.controller;

import com.credithc.baseserv.core.codes.CoreCodes;
import com.credithc.baseserv.core.message.Message;
import com.credithc.baseserv.core.message.MessageFactory;
import com.credithc.customers.manager.service.ScheduleService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author zhukai
 * @date 2019/1/4 17:09
 */
@RestController
@RequestMapping("/manager/yzt/v1")
public class InitDataController {

    private final MessageFactory messageFactory;

    private final ScheduleService scheduleService;

    public InitDataController(MessageFactory messageFactory, ScheduleService scheduleService) {
        this.messageFactory = messageFactory;
        this.scheduleService = scheduleService;
    }

    @PostMapping("/initStatsData")
    public Message initStatsData() {
        String currentDay = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
        scheduleService.statsCustomerCount(currentDay);
        return messageFactory.getInstance(CoreCodes.CORE_SUCCESS);
    }
}
